package com.dlb.andorid.presenter;

import com.dlb.andorid.XAPI;
import com.dlb.andorid.XContract;
import com.dlb.andorid.XPresenter;
import com.dlb.andorid.XServerMsg;
import com.dlb.andorid.bean.ArgAddOrder;
import com.dlb.andorid.bean.Order;
import com.dlb.andorid.bean.ProductBean;
import com.dlb.andorid.bean.ProductDetailBean;
import com.dlb.andorid.bean.ServerResult;

import java.util.HashMap;
import java.util.List;

public class ProductDetailPresenter extends XPresenter {

	XContract.IProductDetailView iView;

	public ProductDetailPresenter(XContract.IProductDetailView iView) {
		super(iView);
		this.iView = iView;
	}

	public void getDetail(long id){
		mModel.getDetail(id);
	}

	public void getRecommend(){
		mModel.getRecommendProducts();
	}

	public void addCar(long id, String userId, int num, long typeId, float price) {
		mModel.addCar(id, userId, num, typeId, price);
	}

	public void addOrder(ArgAddOrder arg){
		mModel.addOrder(arg);
	}

	public void addFav(long commodity_id, int typex){
		mModel.addFav(commodity_id, typex);
	}

	@Override
	public void onDataSuccess(int vocational_id, HashMap<String, Object> exData, Object data) {
		super.onDataSuccess(vocational_id, exData, data);
		switch (vocational_id){
			case XAPI.GET_PRODUCT_DETAIL_VOCATIONAL_ID:
				iView.getDetailSuccess(((XServerMsg<ProductDetailBean>) data).getData());
				break;
			case XAPI.GET_RECONMEEND_PRODUCTS_VOCATIONAL_ID:
				iView.getRecommendProductsSuccess(((XServerMsg<List<ProductBean>>) data).getData());
				break;
			case XAPI.ADD_CAR_VOCATIONAL_ID:
				iView.addCarSuccess(((XServerMsg<ServerResult>) data).getData());
				break;
			case XAPI.ADD_FAV_VOCATIONAL_ID:
				iView.addFavSuccess((XServerMsg) data);
				break;
			case XAPI.ADD_ORDER_VOCATIONAL_ID:
				iView.addOrderSuccess(((XServerMsg<Order>) data).getData());
				break;
		}
	}
}
